package com.sgs.carbon.web.modules.common.dal.mapper.auth;

import com.sgs.carbon.common.pojo.PageResult;
import com.sgs.carbon.starter.mybatis.core.mapper.BaseMapperX;
import com.sgs.carbon.starter.mybatis.core.query.QueryWrapperX;
import com.sgs.carbon.web.modules.common.controller.auth.vo.session.SysUserSessionPageReqVO;
import com.sgs.carbon.web.modules.common.dal.dataobject.auth.SysUserSessionDO;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * 用户 Session Mapper
 *
 * @author Dave Liu
 * @date 2021-10-07
 */
public interface SysUserSessionMapper extends BaseMapperX<SysUserSessionDO> {

    default PageResult<SysUserSessionDO> selectPage(SysUserSessionPageReqVO reqVO, Collection<Long> userIds) {
        return selectPage(reqVO, new QueryWrapperX<SysUserSessionDO>()
                .inIfPresent("user_id", userIds)
                .likeIfPresent("user_ip", reqVO.getUserIp()));
    }

    default List<SysUserSessionDO> selectListBySessionTimoutLt() {
        return selectList(new QueryWrapperX<SysUserSessionDO>().lt("session_timeout", new Date()));
    }

}
